using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HealthCollectible : MonoBehaviour
{
    // 音频资源
    public AudioClip audioClip;
    // 粒子特效
    public GameObject effectParticle;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        // Debug.Log("发生碰撞的物体是：" + collision);
        RubyController rubyController = collision.GetComponent<RubyController>();
        // 当前检测的游戏物体对象身上是否有RubyController脚本
        if (rubyController != null)
        {
            // Ruby是否满血
            if (rubyController.Health < rubyController.maxHealth)
            {
                rubyController.ChangeHealth(1);
                rubyController.PlaySound(audioClip); // 播放音效
                Destroy(gameObject); // 销毁当前游戏对象
                Instantiate(effectParticle, transform.position, Quaternion.identity); // 播放特效
            }
        }
    }
}
